﻿using System;
using Obj;
using DAL;
using System.Collections.Generic;


namespace BLL
{
    /// <summary>
    /// Summary description for BLLAutomovel
    /// </summary>
    public class BLLAutomovel
    {
        public int Save(objAutomovel automovel, action acao)
        {
            int ret = 0;

            switch (acao)
            {
                case action.INSERT:
                    ret = Insert(automovel);
                    break;
                case action.UPDATE:
                    ret = Update(automovel);
                    break;
                case action.DELETE:
                    ret = Delete(automovel);
                    break;
                default:
                    throw new Exception("Operação Inválida");
            }

            return ret;

        }

        private int Insert(objAutomovel automovel)
        {
            int ret = 0;
            if (int.Parse(automovel.AutomovelID.ToString()) != 0)
                throw new Exception("Código do automovel Inválido");

            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            ret = sqlAutomovel.Insert(automovel);
            return ret;

        }

        private int Update(objAutomovel automovel)
        {
            if (int.Parse(automovel.AutomovelID.ToString()) <= 0)
                throw new Exception("Codigo do automovel Inválido");

            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            if (sqlAutomovel.Update(automovel))
                return 1;
            else
                return 0;
        }

        private int Delete(objAutomovel automovel)
        {
            if (int.Parse(automovel.AutomovelID.ToString()) <= 0)
                throw new Exception("Codigo do Automovel Inválido");

            
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
           

            if (sqlAutomovel.Delete(automovel.AutomovelID))
                return 1;
            else
                return 0;
        }

        public objAutomovel automovel(objAutomovel automovel)
        {
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            if (automovel.AutomovelID == 0)
            {
                return sqlAutomovel.SelectByPasta(automovel.Pasta);
            }
            else
            {
                return sqlAutomovel.SelectByID(automovel.AutomovelID);
            }
        }

        public List<objAutomovel> lstAutomovelByGaragem(int garagemID)
        {
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            return sqlAutomovel.SelectByGaragem(garagemID);
        }
        public List<objAutomovel> lstAutomovel()
        {
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            return sqlAutomovel.SelectAll();
        }
        public List<objAutomovel> lstAutomovel(objAutomovel automovel)
        {
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            return sqlAutomovel.SelectAll(automovel);
        }
        public List<objAutomovel> lstAutomovelRelacionado(objAutomovel automovel)
        {
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            return sqlAutomovel.SelectRelacionados(automovel);
        }
        public List<objAutomovel> lstTopAutomovel(objAutomovel automovel)
        {
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            return sqlAutomovel.SelectTop(automovel);
        }

        public List<objAutomovel> lstVitrine() 
        {
            SQLAutomovel sqlAutomovel = new SQLAutomovel();
            return sqlAutomovel.SelectVitrine();
        }

    }
}